package com.swh.xbsc.mapper;


import com.alibaba.excel.util.StringUtils;
import org.apache.ibatis.jdbc.SQL;

import java.util.Map;

/**
 * @Author: swh
 * @Description:
 * @Date: 2020/11/18 18:14
 * @Version: 1.0
 */
public class ArticleProvider {
    public String selectPage(Map<String, Object> map) {
        return new SQL() {{
            SELECT("  ar.*, us.username userName ");
            FROM("article ar, `user` us ");
            WHERE("ar.user_id = us.id");
            if (map.containsKey("title") && !StringUtils.isEmpty(map.get("title"))) {
                WHERE(" ar.title LIKE CONCAT('%',#{title},'%')");
            }
        }}.toString();
    }

    public String selectPage2(Map<String, Object> map) {
        return new SQL() {{
            SELECT("*");
            FROM("article");
            WHERE("collection =0");
            if (map.containsKey("title") && !StringUtils.isEmpty(map.get("title"))) {
                WHERE("title LIKE CONCAT('%',#{title},'%')");
            }
        }}.toString();
    }
}
